<?php
// +----------------------------------------------------------------------
// | ThinkSnS
// +----------------------------------------------------------------------
// | Copyright (c) 2009 http://www.thinksns.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Nonant <nonant@163.com>
// +----------------------------------------------------------------------
// $Id$
class PublicAction extends BaseAction  {

	//登陆
	function login(){
		$this->display();
	}

	//退出
	function logout(){
		unset($_SESSION['SociaxAdmin']);
		$this->assign('jumpUrl','index.php');
		$this->success('退出成功');
	}

	//验证登陆
	function checklogin(){

//		$strVerify   = h($_POST['verify']);
//		if(md5($strVerify)!=$_SESSION['verify']){
//			$this->error('验证码错误');
//			exit;
//		}

		if($this->mid){
			$map['uid']		=	t($_POST['uid']);
		}else{
			$map['uname']	=	t($_POST['account']);
		}

		$user = D('User')->where($map)->find();
		if(!$user){
			$this->error("这个帐号不存在！");
		}

		$userGroup	=	model('UserGroup');
		$isAdmin	=	$userGroup->isAdmin($user['uid']);
		if(!$isAdmin){
			$this->error("你不是管理员，不能登陆后台！");
		}

		$username	=	t($user['uname']);
		$password	=	t($_POST['password']);
		if(empty($password)){
			$this->error("密码不能为空！");
		}
		$passport	=	service('Passport');
		$isLogged		=	$passport->isLogged($username,$password);
		if($isLogged){
			$_SESSION['SociaxAdmin']	=	intval($user['uid']);
			$this->assign('jumpUrl',U('/Index/index'));
            $this->success('登陆成功');
		}else{
			$this->error('用户密码错误！');
		}
	}

	//验证码
    function verify()
    {
        import("ORG.Util.Image");
        Image::buildImageVerify();
    }
}

?>